/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MetricsRetriever;

import Interfaces.Rankable;
import java.util.Date;

/**
 *
 * @author Manuel
 */
public class ProjectPackage implements Rankable {


    private String name;
    private String description;
    private int rank;
    private Date date;
    private long size;
    private boolean featured;
    private Date uploadDate;
    private String projectName;
    private int downloadNumber;

    public ProjectPackage(){
        rank = 0;
        projectName = "";
    }

    public ProjectPackage(String pname){
        rank = 0;
        projectName = pname;
    }

    //gives the project archieve a ranking to recognize which is the most probable wanted
    public void rank(long avgSize,long avgDownloads){
        if(this.featured)
            rank += 4;
        if(this.name.contains("jar"))
            rank +=2;
        if(this.description.contains("class") || this.description.contains("bin") || this.description.contains("deployment") || this.description.contains("built")|| this.description.contains("java")) //SUBSTITUTE WITH LANGUAGE OF POJECT
            rank += 2;
        if(this.description.contains("release") || this.description.contains("distribution") || this.description.contains("stable") || this.description.contains("linux") || this.description.contains("unix"))
            rank ++;
        if(this.description.contains("deprecated"))
            rank-=4;
        if(this.description.contains("doc") || this.description.contains("html") || this.description.contains("pdf"))
            rank-=2;
        if(this.name.substring(name.lastIndexOf("/")).contains(projectName))
            rank+=3;

        //
        int pointsForSize = (int) ((this.size - avgSize) * 10 / avgSize)/6;
        rank += pointsForSize;

        long monthInMillis = 3000000000l;
        int monthsPassed = (int) ((new Date().getTime() - date.getTime()) / monthInMillis) + 1;
        int pointsForDownloads = (int) (Math.abs(this.downloadNumber - avgDownloads) * 10 / avgDownloads)/4;
        pointsForDownloads = pointsForDownloads/(monthsPassed * monthsPassed);
        rank += pointsForDownloads;
        rank -= (int) (monthsPassed/4);
        
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description + this.name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public boolean isFeatured() {
        return featured;
    }

    public void setFeatured(boolean featured) {
        this.featured = featured;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date d) {
        this.date = d;
    }

    public Date getUploadDate() {
        return uploadDate;
    }

    public void setUploadDate(Date uploadDate) {
        this.uploadDate = uploadDate;
    }

    public int getDownloadNumber() {
        return downloadNumber;
    }

    public void setDownloadNumber(int downloadNumber) {
        this.downloadNumber = downloadNumber;
    }



}
